package com.nuo.laboratory.juc.collection;

/**
 * @author LGC
 * @date 2022/3/27 16:57
 */
public class MyArray {
    public static void main(String[] args) {
        int[] arrs = new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9};
        int target = 3;
        int start = 0;
        int end = arrs.length - 1;
        int mid = (start + end) / 2;
        int rs = -1;
        while (true) {
            if (start >= end) {
                break;
            }
            if (arrs[mid] == target) {
                rs = mid;
                break;
            } else {
                if (arrs[mid] > target) {
                    start = mid + 1;
                }
                if (arrs[mid] < target) {
                    end = mid - 1;
                }
                mid = (start + end) / 2;
            }
        }
        System.out.println(rs);
    }
}
